package com.enqualcomm.kids.view;

import android.text.InputFilter;
import android.text.Spanned;

import java.io.UnsupportedEncodingException;

public class MyInputFilter implements InputFilter {

	@Override
	public CharSequence filter(CharSequence source, int start, int end,
			Spanned dest, int dstart, int dend) {
		
		
		try {
			int destLen = dest.toString().getBytes("GB18030").length;
			int sourceLen = source.toString().getBytes("GB18030").length;
			if (destLen + sourceLen > 12) {
				return "";
			}
			
			//如果按回退键
			if (source.length() < 1 && (dend - dstart >= 1)) {
				return dest.subSequence(dstart, dend - 1);
			}
			return source;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}         

		return source;
	}
}
